<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @cancel="close"
    style="top:50px"
    cancelText="关闭">

    <a-card :bordered="false">
      <!-- 查询区域 -->
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <a-row>
        <a-col :span="8" >
          <template>
            <a-timeline mode="alternate">
              <a-timeline-item :key="index" color="blue" v-for="(item,index) in dataSource">
                <p>{{item.business_dictText}} 数量 {{item.quantity}}</p>
                <p>{{item.operationTime}}</p>
              </a-timeline-item>
            </a-timeline>
          </template>
            <a-form-model-item label="入库单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              {{code}}
            </a-form-model-item>
            <a-form-model-item label="库存数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              {{quantity}}
            </a-form-model-item></a-col>
        <a-col :span="16" >
      <div>
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          class="j-table-force-nowrap"
          :scroll="{x:true}"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange"/>
      </div>
        </a-col>
      </a-row>
    </a-card>

  </j-modal>
</template>
<script>
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import { getAction, putAction } from '@api/manage'
import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'


export default {
  name: 'BussInOutDetailListModal',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  // props: ['category', "modalWidth",],
  props: {
    category: {
      type: String
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250
    },
    checkval: {
      type: String,
      default: 'radio'
    },
    supplierId: {
      type: String,
      required: false
    },
    code: {
      type: String
    },
    quantity: {
      type: String
    },
  },
  watch: {
    category(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to:', newValue);
      this.queryParam = {id: newValue};
      this.loadData();
    }
  },
  data() {
    return {
      description: '库存明细页面',
      visible: false,
      title: '库存明细',
      disableMixinCreated: true,
      queryParam: {id: this.category | 1},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title: '操作人',
          align:"center",
          dataIndex: 'operator',
        },
        {
          title: '操作时间',
          align:"center",
          dataIndex: 'operationTime',
        },
        {
          title: '业务',
          align:"center",
          dataIndex: 'business_dictText',
        },
        {
          title: '业务类型',
          align:"center",
          dataIndex: 'businessType_dictText',
        },
        {
          title: '数量',
          align:"center",
          dataIndex: 'quantity',
        },
        // {
        //   title: '单位',
        //   align:"center",
        //   dataIndex: 'meUnit_dictText',
        // },
        {
          title: '条码',
          align:"center",
          dataIndex: 'barCode',
        },
        {
          title: '业务编号',
          align:"center",
          dataIndex: 'businessCode',
        },
        {
          title: '备注',
          align:"center",
          dataIndex: 'remark',
        },
      ],
      url: {
        list: "/inventory/bussInventory/queryBussInventoryInoutDetailsByDetailId",
        delete: "/inventory/bussInventory/delete",
        deleteBatch: "/inventory/bussInventory/deleteBatch",
        exportXlsUrl: "/inventory/bussInventory/exportXls",
        importExcelUrl: "inventory/bussInventory/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleSubmit() {
      this.getGoodsSelectRows();
      this.searchReset(false)
      this.onClearSelected();
      this.close();
    },
    add() {
      this.showModal();
    },

    showModal() {
      this.dataSource = []
      this.visible = true;
      this.loadData();
    },
    getGoodsSelectRows() {
      let selectedRow = null;
      if(this.checkval=='radio'){
         selectedRow = this.selectionRows[0];
      }else{
         selectedRow = this.selectedRowKeys
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit("inventoryOk", selectedRow);
    },
    initDictConfig() {
    },
    close() {
      this.searchReset(false);
      this.visible = false;
    },
    getSuperFieldList() {
      let fieldList=[];
      fieldList.push({type:'string',value:'operator',text:'操作人',dictCode:''})
      fieldList.push({type:'string',value:'operationTime',text:'操作时间',dictCode:''})
      fieldList.push({type:'string',value:'business',text:'业务',dictCode:'kc_business'})
      fieldList.push({type:'string',value:'businessType',text:'业务类型',dictCode:'kc_business_type'})
      fieldList.push({type:'BigDecimal',value:'quantity',text:'数量',dictCode:''})
      fieldList.push({type:'string',value:'meUnit',text:'单位',dictCode:'ji_unit'})
      fieldList.push({type:'string',value:'barCode',text:'条码',dictCode:''})
      fieldList.push({type:'string',value:'businessCode',text:'业务编号',dictCode:''})
      fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
      this.superFieldList = fieldList
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();//查询条件
      params.supplierId = this.supplierId;
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result;
          if (res.result.total) {
            this.ipagination.total = res.result.total;
          } else {
            this.ipagination.total = 0;
          }
          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

</style>